<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html><html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>供应商管理</title>
    <style>
        .newtitle {
            PADDING-LEFT: 15px;
            BACKGROUND: url('');
            PADDING-BOTTOM: 4px;
            BORDER-LEFT: #c0dcf2 1px solid;
        }
    </style>
    <jsp:include page="easyuiIncludeJS.jsp"/>
    <script type="text/javascript">
        $(function () {
            var pager = $(".easyui-datagrid").datagrid('getPager');
            $(pager).pagination({
                total:${pager.totalRows},
                pageSize:${pager.pageRow},
                displayMsg: '{from}-{to}/{total}',
                pageNumber:${pager.cur_page},
                afterPageText: '页，共{pages}页',
                pageList: [5, 10, 20, 30, 50, 100],
                loading: false,
                showPageList: true,
                showRefresh: true,
                //刷新方法
                onBeforeRefresh: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/supplier/supplierlist?cur_page=" + p + "&pageRow=" + s;
                },
                onSelectPage: function (p, s) {
                    location.href = "${pageContext.request.contextPath }/admin/supplier/supplierlist?cur_page=" + p + "&pageRow=" + s;
                }
            });
        });
        function delcalss(supplierId){
        	if(!confirm('删除确定')){
        		return;
        	}
           var url = "${pageContext.request.contextPath}/admin/supplier/supplierdel";
            var supplierId = supplierId;
            $.post(
                url,
                {
                    "supplierId":supplierId
                },
                function (data) {
                    /*
                	if(data == 1){
                        alert("班级管理中有数据不能删除!");
                        return;
                    }
                    if(data == 0){
                        del(supplierId);
                    }
                    */
                    location.href = "${pageContext.request.contextPath }/admin/supplier/supplierlist";
                },
                "json"
            );
        }
        function del(supplierId) {
            var url = "${pageContext.request.contextPath}/admin/supplier/supplierdel";
            if(confirm("删除确认")){
                $.post(
                    url,
                    {
                        "supplierId":supplierId
                    },
                    function (data) {
                        window.location.href = "${pageContext.request.contextPath}/admin/supplier/supplierlist";
                    },
                    "json"
                );
                return;
            }

        }

        function save() {
            if ($("#supplierCode").val()==""){
                alert("请输入供应商编码");
                $("#supplierCode").focus();
                return;
            }
            if ($("#supplierName").val()==""){
                alert("请输入供应商名称");
                $("#supplierName").focus();
                return;
            }
            var url="${pageContext.request.contextPath}/admin/supplier/init"
            var supplierId=$("#supplierId").val();
            var supplierCode=$("#supplierCode").val();
            var supplierName=$("#supplierName").val();
            var addr=$("#addr").val();
            var country = $("#country").val();
            var province = $("#province").val();
            var city = $("#city").val();
            var contact = $("#contact").val();
            var tel = $("#tel").val();
            var email = $("#email").val();
            var phone = $("#phone").val();
            var qqcode = $("#qqcode").val();
            var taxId = $("#taxId").val();
            var bankName = $("#bankName").val();
            var bankAccount = $("#bankAccount").val();
            var bankChairman = $("#bankChairman").val();
            var remark = $("#remark").val();
            $.post(
                url,
                {
                    "supplierId":supplierId,
                    "supplierName":supplierName,
                    "supplierCode":supplierCode,
                    "addr":addr,
                    "country":country,
                    "province":province,
                    "city":city,
                    "contact":contact,
                    "tel":tel,
                    "email":email,
                    "phone":phone,
                    "qqcode":qqcode,
                    "taxId":taxId,
                    "bankName":bankName,
                    "bankAccount":bankAccount,
                    "bankChairman":bankChairman,
                    "remark":remark
                },
                function(data){
                    window.location.href = "${pageContext.request.contextPath}/admin/supplier/supplierlist";
                },
                "json"
            );
        }

        function test(value, res) {
        	var supplierId=res.supplierId;
            var supplierCode=res.supplierCode;
            var supplierName=res.supplierName;
            var addr=res.addr;
            var country = res.country;
            var province = res.province;
            var city = res.city;
            var contact = res.contact;
            var tel = res.tel;
            var email = res.email;
            var phone = res.phone;
            var qqcode = res.qqcode;
            var taxId = res.taxId;
            var bankName = res.bankName;
            var bankAccount = res.bankAccount;
            var bankChairman = res.bankChairman;
            var remark = res.remark;
            var url="${pageContext.request.contextPath}/admin/supplier/json";
            $.post(
                url,
                {
                	"supplierId":supplierId,
                    "supplierName":supplierName,
                    "supplierCode":supplierCode,
                    "addr":addr,
                    "country":country,
                    "province":province,
                    "city":city,
                    "contact":contact,
                    "tel":tel,
                    "email":email,
                    "phone":phone,
                    "qqcode":qqcode,
                    "taxId":taxId,
                    "bankName":bankName,
                    "bankAccount":bankAccount,
                    "bankChairman":bankChairman,
                    "remark":remark
                },
                updemp,
                "json"
            );
        }
        function updemp(data) {
            $("#supplierId").val(data.supplierList.supplierId);
            $("#supplierName").val(data.supplierList.supplierName);
            $("#supplierCode").val(data.supplierList.supplierCode);
            $("#addr").val(data.supplierList.addr);
            $("#country").val(data.supplierList.country);
            $("#province").val(data.supplierList.province);
            $("#city").val(data.supplierList.city);
            $("#contact").val(data.supplierList.contact);
            $("#tel").val(data.supplierList.tel);
            $("#email").val(data.supplierList.email);
            $("#phone").val(data.supplierList.phone);
            $("#qqcode").val(data.supplierList.qqcode);
            $("#taxId").val(data.supplierList.taxId);
            $("#bankName").val(data.supplierList.bankName);
            $("#bankAccount").val(data.supplierList.bankAccount);
            $("#bankChairman").val(data.supplierList.bankChairman);
            $("#remark").val(data.supplierList.remark);
        }
        function closeSubmit() {
        	$("#supplierId").val("");
            $("#supplierName").val("");
            $("#supplierCode").val("");
            $("#addr").val("");
            $("#country").val("");
            $("#province").val("");
            $("#city").val("");
            $("#contact").val("");
            $("#tel").val("");
            $("#email").val("");
            $("#phone").val("");
            $("#qqcode").val("");
            $("#taxId").val("");
            $("#bankName").val("");
            $("#bankAccount").val("");
            $("#bankChairman").val("");
            $("#remark").val("");
        }

    </script>
</head>
<body>

<table  class="easyui-datagrid" pagination="true" fitColumns="auto"  style="height:300px" singleSelect="true" data-options="onClickRow:test">
    <thead>
    <tr>
        <th align="center" width="80" field="supplierId">序号</th>
        <th align="center" width="100" field="supplierCode">供应商编码</th>
        <th align="center" width="100" field="supplierName">供应商名称</th>
        <th align="center" width="80" field="contact">联系人</th>
        <th align="center" width="120" field="tel">联系人电话</th>
        <th align="center" width="120" field="phone">手机</th>
        <th align="center" width="100" field="qqcode">QQ号码</th>
        <th align="center" width="100" field="email">邮箱</th>
        <th align="center" width="100" field="taxId">纳税编号</th>
        <th align="center" width="100" field="bankName">开户银行</th>
        <th align="center" width="100" field="bankAccount">银行账号</th>
        <th align="center" width="100" field="bankChairman">户名</th>
        <th align="center" width="100" field="country">国家</th>
        <th align="center" width="100" field="province">省份</th>
        <th align="center" width="100" field="city">城市</th>
        <th align="center" width="100" field="addr">地址</th>
        <th align="center" width="100" field="remark">备注</th>
        <th align="center" field="opt">操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${supplierList}" var="d">
        <tr>
            <td>${d.supplierId}</td>
            <td>${d.supplierCode}</td>
            <td>${d.supplierName}</td>
            <td>${d.contact}</td>
            <td>${d.tel}</td>
            <td>${d.phone}</td>
            <td>${d.qqcode}</td>
            <td>${d.email}</td>
            <td>${d.taxId}</td>
            <td>${d.bankName}</td>
            <td>${d.bankAccount}</td>
            <td>${d.bankChairman}</td>
            <td>${d.country}</td>
            <td>${d.province}</td>
            <td>${d.city}</td>
            <td>${d.addr}</td>
            <td>${d.remark}</td>
            <td>
                <a href="javascript:void(0);" class="easyui-linkbutton" plain="true" icon="icon-remove"
                   onclick='delcalss(${d.supplierId});'> 删除</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div id="tt" class="easyui-tabs" style="height:260px">
    <div title="供应商管理" data-options="closable:false,cache:false" style="padding:0px;">
	    <div class="newtitle">
	        <th>
				<a class="easyui-linkbutton " href="javascript:void(0);" plain="true" icon="icon-add" onclick="closeSubmit();">新增</a>
	            <a class="easyui-linkbutton " href="javascript:void(0);" plain="true" icon="icon-save" onclick="save();">保存</a>
	        </th>
	    </div>
        <form id="td" name="td" method="post" style="margin-left: 50px;">
            <hidden id="supplierId" name="supplierId"></hidden>
            <table border="0" width="100%">
            	<tr height="30">
	                <td align="right"><label class="label-top">供应商编码:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="supplierCode" name="supplierCode" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">供应商名称:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="supplierName" name="supplierName" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">联系人:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="contact" name="contact" style="width: 220px;"></td>
                </tr>
            	<tr height="30">
	                <td align="right"><label class="label-top">联系人电话:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="tel" name="tel" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">邮箱:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="email" name="email" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">手机:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="phone" name="phone" style="width: 220px;"></td>
                </tr>
            	<tr height="30">
	                <td align="right"><label class="label-top">QQ号码:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="qqcode" name="qqcode" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">纳税编号:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="taxId" name="taxId" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">开户银行:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="bankName" name="bankName" style="width: 220px;"></td>
                </tr>
            	<tr height="30">
	                <td align="right"><label class="label-top">银行账号:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="bankAccount" name="bankAccount" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">户名:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="bankChairman" name="bankChairman" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">单位地址:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="addr" name="addr" style="width: 220px;"></td>
                </tr>
            	<tr height="30">
	                <td align="right"><label class="label-top">所属国家:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="country" name="country" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">省份:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="province" name="province" style="width: 220px;"></td>
	                <td align="right"><label class="label-top">城市:</label></td>
	                <td><input class="easyui-textbox" data-options="required:true" id="city" name="city" style="width: 220px;"></td>
                </tr>

            	<tr height="40">
	                <td align="right"><label class="label-top">供应商描述:</label></td>
	                <td colspan="5"><input class="easyui-textbox" data-options="required:true" id="remark" name="remark" style="width: 1020px;"></td>
                </tr>
            </table>
        </form>
    </div>
</div>
</body>
</html>
